﻿@model bool?

@{
    // make use of nullable attribute values
    var yesSelected = Model.HasValue && Model.Value ? "active" : null;
    var noSelected = (Model.HasValue && !Model.Value)
        || (!Model.HasValue && ViewData.ModelMetadata.IsNullableValueType)
        ? "active"
        : null;
    var noSelection = !Model.HasValue ? "active" : null;

    // get the name of the ID - this is to support multiple fields
    var htmlField = ViewData.TemplateInfo.HtmlFieldPrefix;
}

@Html.HiddenFor(model => model)

<div class="btn-group" data-toggle="buttons">
    <label class="btn btn-info @yesSelected">
        <input type="radio" class="bool-@htmlField" onchange="javascript:$('#@htmlField').val(true);" /> Yes
    </label>
    <label class="btn btn-info @noSelected">
        <input type="radio" class="bool-@htmlField" onchange="javascript:$('#@htmlField').val(false);" /> No
    </label>

    @if (ViewData.ModelMetadata.IsNullableValueType)
    {
        <label class="btn btn-info @noSelection">
            <input type="radio" class="bool-@htmlField" onclick="javascript:$('#@htmlField').val('');" />Do Not Set
        </label>
    }

</div>